package br.com.empresa.view;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import br.com.empresa.dao.UsuarioDAO;
import br.com.empresa.modelo.Usuario;

public class LoginUsuarioGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txUsuario;
	private JPasswordField txPasswordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LoginUsuarioGUI frame = new LoginUsuarioGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LoginUsuarioGUI() {
		setTitle("Betha Sistemas");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 287, 266);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 0, 271, 227);
		contentPane.add(panel);
		panel.setLayout(null);

		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.DARK_GRAY);
		panel_1.setBounds(0, 0, 530, 46);
		panel.add(panel_1);
		panel_1.setLayout(null);

		JLabel lblNewLabel = new JLabel("ENTRE COM SEU LOGIN");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(10, 11, 236, 20);
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
		panel_1.add(lblNewLabel);

		JPanel panel_2 = new JPanel();
		panel_2.setBackground(Color.DARK_GRAY);
		panel_2.setBounds(0, 213, 270, 21);
		panel.add(panel_2);
		panel_2.setLayout(null);

		JLabel lblDesenvolvido = new JLabel(
				"Desenvolvido por Daniel Pl\u00E1cido");
		lblDesenvolvido.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDesenvolvido.setForeground(Color.WHITE);
		lblDesenvolvido.setBounds(0, 0, 270, 14);
		panel_2.add(lblDesenvolvido);

		JLabel lblNewLabel_1 = new JLabel("Usu\u00E1rio:");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblNewLabel_1.setBounds(20, 67, 65, 14);
		panel.add(lblNewLabel_1);

		JLabel lblNome = new JLabel("Senha:");
		lblNome.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblNome.setBounds(20, 109, 65, 14);
		panel.add(lblNome);

		txUsuario = new JTextField();
		txUsuario.setBounds(95, 64, 156, 20);
		panel.add(txUsuario);
		txUsuario.setColumns(10);

		JButton btnLogin = new JButton("Login");
		btnLogin.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			public void actionPerformed(ActionEvent arg0) {

				Usuario userObjCheck = new Usuario();
				userObjCheck.setLoginUsuario(txUsuario.getText());
				userObjCheck.setSenhaUsuario(txPasswordField.getText());
				UsuarioDAO daoObj = new UsuarioDAO();
				boolean checkReturn = daoObj.login(userObjCheck);

				if (checkReturn == true) {
					dispose();
					MenuSistemaGUI gui = new MenuSistemaGUI();
					gui.setVisible(true);
				}
			}
		});
		btnLogin.setBounds(20, 179, 89, 23);
		panel.add(btnLogin);

		JButton btnLimpar = new JButton("Limpar");
		btnLimpar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				txUsuario.setText(null);
				txPasswordField.setText(null);

			}
		});
		btnLimpar.setBounds(136, 179, 89, 23);
		panel.add(btnLimpar);

		txPasswordField = new JPasswordField();
		txPasswordField.setBounds(95, 107, 156, 20);
		panel.add(txPasswordField);
	}
}
